﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="MicroBlog.aspx.cs" Inherits="aspnet_server_push.MicroBlog.MicroBlog" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Welcome to Microblog</title>
    <script src="../Scripts/jquery-1.6.4.js" type="text/javascript"></script>
    <script src="../Scripts/jquery.signalR.js" type="text/javascript"></script>
    <script src="../signalr/hubs"></script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <div>
            <span>MicroBlog ID:</span><input type="text" id="uid" name="uid" value=" " />
            <input type="button" name="refreshTimeline" id="refreshTimeline" value="Refresh Timeline" />
        </div>
        <ul id="messages"></ul>
    </div>
    </form>
    <script type="text/javascript">
        $(function () {
            // Proxy created on the fly
            var conn = $.connection.microBlogServer;

            // Declare a function so the server can invoke it
            conn.newMessage = function (msg) {
                $('#messages').append('<li>' + msg + '</li>');
            };
            conn.notify = function(notice) {
                $('#messages').append('<li>[system notice]:\t' + notice + '</li>');
            }

            // Start the connection
            $.connection.hub.start();


            //call server side refresh when all things ready
            $("#refreshTimeline").click(function() {
                conn.refreshTimeline($('#uid').val());
            });
        });
    </script>
</body>
</html>
